#!/usr/bin/env python
# -*- coding:utf-8 -*-
# @Time: 2023/1/5 0:42
# @Author: 周阳
# @Email: 100530987@qq.com
# @File：config.py
import os
import configparser # 读取ini的库
from common.consts import CONFIG_PATH

class Config(object):
    # 封装获取conf文件类
    def __init__(self, filename="config.ini"): # 实例化的时候默认读取ini文件
        self.cf = configparser.ConfigParser()
        self.log_path = os.path.join(CONFIG_PATH, filename) # 组装confif.ini的绝对路径
        self.cf.read(self.log_path, encoding="utf-8")
    def get_conf(self, section, option):
        return self.cf.get(section, option)
    def set_conf(self, section, option, value):
        self.cf.set(section, option,value)
        with open(self.log_path, 'w+') as f:
            return self.cf.write(f)
    def add_section(self, section): # 添加扇区
        self.cf.add_section(section)
        with open(self.log_path, 'w+') as f:
            return self.cf.write(f)
    def get_runtime(self, option):
        return self.get_conf("runtime",option)
    def get_server(self, option):
        return self.get_conf("server", option)
    def get_db_test(self, option):
        return self.get_conf("db_test", option)
    def get_email(self, option):
        return self.get_conf("email", option)